function checkWindowSize(){
    if(jQuery(window).width() < 1023){
      jQuery('.sidebar-widgets').insertAfter(jQuery('.blog-articles, .single-post-page, .single-gallery-post'));
      jQuery('#sidebar footer').insertAfter(jQuery('#main .container'));
      jQuery('.sidebar-widget').addClass('grid-4');
    }
    else{
      jQuery('.sidebar-widgets').insertAfter(jQuery('.primary-navigation'));
      jQuery('#main footer').insertAfter(jQuery('#sidebar .sidebar-widgets'));
      jQuery('.sidebar-widget').removeClass('grid-4');
    }
  } 
  checkWindowSize();
  jQuery(window).resize(checkWindowSize); 